<template>
	<div class="login-wrap">
		<br>
<!--		<div align="center" class="ms-logo"><font>-->
<!--			闽侯烟草案件管理平台-->
<!--		</font></div>-->
		<div class="ms-login">
			<br><br>
			<div align="center" ><img src="../assets/img/login_logo.png" height="88" ></div>
			<div class="ms-title">大数据管理系统登录</div>
			<el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
				<el-form-item prop="username">
					<el-input v-model="param.username" placeholder="请输入账号" >
						<template #prepend>
							<el-button :icon="User"></el-button>
						</template>
					</el-input>
				</el-form-item>
				<el-form-item prop="password">
					<el-input
							type="password"
							placeholder="请输入密码"
							v-model="param.password"
							@keyup.enter="login_da"
					>
						<template #prepend>
							<el-button :icon="Lock"></el-button>
						</template>
					</el-input>
				</el-form-item>
				<div class="login-btn">
					<el-button type="primary" @click="login_da">登录</el-button>
				</div>
				<!--				<p class="login-tips">Tips : 用户名和密码随便填。</p>-->
			</el-form>
		</div>
	</div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue';
import { useTagsStore } from '../store/tags';
import { usePermissStore } from '../store/permiss';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { Lock, User } from '@element-plus/icons-vue';
import {fetchData_case, fetchData_get_real_message, login_data} from "../api";
import lineHeightList from "wangeditor/dist/menus/lineHeight/lineHeightList";
import splitLine from "wangeditor/dist/menus/split-line";

interface LoginInfo {
username: string;
password: string;
real_name:string;
}


const router = useRouter();
const param = reactive<LoginInfo>({
username: '',
password: '',
real_name:'',
});

const really_message=reactive({
	real_name:''
})

const rules: FormRules = {
username: [
	{
		required: true,
		message: '请输入用户名',
		trigger: 'blur'
	}
],
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],

// real_name:[{ required: true,  trigger: 'blur' }]
};


const login_da = () =>{
	get_real_username(param.username);
login_data(param.username,param.password).then(res => {

	if (res.data.data.flag_password === "success"){
		localStorage.setItem('ms_username', param.username);
		localStorage.setItem('real_name',really_message.real_name);
		permiss.handleSet(res.data.data.permiss);
		localStorage.setItem('ms_keys', JSON.stringify(res.data.data.permiss));
		for (let i=0;i<res.data.data.permiss.length;i++){
			// alert(res.data.data.permiss[i])
			if(res.data.data.permiss[i]===1){
				ElMessage.success('登录成功');
				break;
			}
		}
		router.push('/');
	}
	else {
		if (res.data.data.flag_user_name === "success") {
			ElMessage.error('密码错误');
			return false;
		}
		else {
			ElMessage.error('用户名错误');
			return false;
		}
	}
});
};
// (function (doc, win) {
// 	var docEl = doc.documentElement,
// 			resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
// 			recalc = function () {
// 				var clientWidth = docEl.clientWidth;
// 				if (!clientWidth) return;
// 				if(clientWidth>=640){
// 					docEl.style.fontSize = '100px';
// 				}else{
// 					docEl.style.fontSize = 100 * (clientWidth / 640) + 'px';
// 				}
// 			};
//
// 	if (!doc.addEventListener) return;
// 	win.addEventListener(resizeEvt, recalc, false);
// 	doc.addEventListener('DOMContentLoaded', recalc, false);
// })(document, window);
const get_real_username=(account_number:string)=>{
	fetchData_get_real_message(account_number).then(res=>{
		really_message.real_name=res.data.data.real_name;
	})
}
const permiss = usePermissStore();

const login = ref<FormInstance>();

const tags = useTagsStore();
tags.clearTags();
</script>

<style scoped>

.ms-logo{
	top: 20%;
	font-size:100% ;
	color: white;
	width: 100%;
	height: 100%;
	font-weight:bold;
}

.login-wrap {
	position: relative;
	width: 100%;
	height: 100%;
	background-image: url(../assets/img/a.jpg);
	background-size: 100%;
}
.ms-title {
	width: 100%;
	line-height: 100%;
	text-align: center;
	font-size: 15px;
	color: green;
	/*color: #000000;*/
	/*border-bottom: 1px solid #ddd;*/
}
.ms-login {
	position: relative;
	left: 60%;
	top: 30%;
	width: 23%;
	/*margin: -190px 0 0 -175px;*/
	/*margin: 10% 0 0 10%;*/

	background: rgba(255, 255, 255, 255);
	overflow: hidden;
}
.ms-content {
	padding: 30px 30px;
}
.login-btn {
	text-align: center;


}
.login-btn button {
	width: 100%;
	height: 36px;
	margin-bottom: 10px;
	background: green;
}
.login-tips {
	font-size: 12px;
	line-height: 30px;
	color: #fff;
}
</style>
